#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------

Global Const $bnt_width = 60
Global Const $act_width = 60
Global Const $inp_width = 60
Global Const $lbl_width = $act_width +  $inp_width


Func _main()
   create_gui()
   main_loop()
EndFunc


Func create_gui()
   _DebugOut("start")
   Local $hh = 40 + 20 + 15 * UBound($actions)
   Local $dh = WinGetHandle($dbg_title)
   If @error = 1 Then 
	  _DebugOut("cannot find dbg title")
   Else
	  WinMove($dh, "", 0, $hh + 25, 300, 500)
   EndIf
   Local $l = Search()
   If $l = 0 Then
	  MsgBox(48, "Error","no possible open game")
	  Exit
   EndIf
   If $l >  $max_client Then
	  MsgBox(48, "Error", "to many game open: " & $l & ", but can only " & $max_client)
	  $l = $max_client
   EndIf
   Local $ww = $l * $lbl_width
   If $ww < 100 Then $ww = 100
   $hGUI = GUICreate("nebesa", $ww, $hh,0,0)
   
   $btn_work[0] = $l
   For $i = 1 To $l
	  Local $p = $winlist[$i]
	  $p[$index_btn] = GUICtrlCreateButton("make", ($i - 1) * $lbl_width, 40, $bnt_width, 20)
	  $btn_work[$i] = $p[$index_btn]
	  $winlist[$i] = $p
   Next
   
   $btn_show[0] = $l
   For $i = 1 To $l
	  Local $p = $winlist[$i]
	  $p[$index_btn+1] = GUICtrlCreateLabel($p[0] & "x" & $p[1], ($i - 1) * $lbl_width, 0, $lbl_width, 20)
	  $btn_show[$i] = $p[$index_btn+1]
	  $winlist[$i] = $p
   Next

   $flag_work[0] = $l
   For $i = 1 To $l
	  Local $p = $winlist[$i]
	  Local $r = ($i - 1) * 120
	  Local $t = 0
	  $t += 20
	  $p[$index_label] = GUICtrlCreateLabel("", $r, $t, $lbl_width, 20)
	  $p[$index_flag] = False
	  $flag_work[$i] = False
	  $t += 40
	  Local $ta = UBound($actions)
	  For $j = 0 To  $ta - 1
		 $p[$index_action + $j] = GUICtrlCreateCheckbox($actions[$j][0], $r, $t, $act_width, 15)
		 $p[$index_action + $j + $ta] = GUICtrlCreateInput($actions[$j][2], $r + $act_width, $t, $inp_width, 15)
		 ;_DebugOut("create input('" & $actions[$j][2] & "'): " & $p[$index_action + $j + $ta] & " on " & ($index_action + $j + $ta))
		 $v = GUICtrlSetState($p[$index_action + $j], $GUI_UNCHECKED)
		 $t += 15
	  Next
	  $winlist[$i] = $p
   Next

   ;prepare_win()
   GUISwitch($hGUI)

   GUISetState(@SW_SHOW,$hGUI)
   WinActivate($hGUI)
EndFunc

Func main_loop()
   While True
	  Local $msg = GUIGetMsg()
	  Switch $msg
		 Case $GUI_EVENT_CLOSE
			ExitLoop
		 ;Case $btn_ok
			;StoreTestResult()
		 Case $btn_work[1] To $btn_work[$btn_work[0]]
			Work($msg - $btn_work[1] + 1)
		 Case $btn_show[1] To $btn_show[$btn_show[0]]
			Show($msg - $btn_show[1] + 1)
	  EndSwitch
   WEnd
EndFunc

